import 'package:aitao_flutter/common_ui/loading_widget.dart';
import 'package:aitao_flutter/mine/controller/certification_controller.dart';
import 'package:aitao_flutter/style/box_style.dart';
import 'package:aitao_flutter/style/edgeInsets_style.dart';
import 'package:aitao_flutter/style/radius_style.dart';
import 'package:aitao_flutter/style/text_style.dart';
import 'package:aitao_flutter/utils/sp_utils.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../common_ui/back_nav.dart';
import '../../res/r.dart';
import '../../style/color_style.dart';

class CertificationPage extends StatefulWidget {
  const CertificationPage({super.key});

  @override
  State<CertificationPage> createState() => _CertificationPageState();
}

class _CertificationPageState extends State<CertificationPage> {
  final CertificationController controller = Get.put(CertificationController());
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: BackNavigation(
        title: '女神认证',
        rightBtnCallBack: () {
          controller.submitClick();
        },
        rightTitle: controller.certificationModel?.inAudit == 0 ? '提交' : '审核中',
        rightTitleColor: controller.certificationModel?.inAudit == 0
            ? ColorStyle.themeColor
            : ColorStyle.aaaaaaColor,
      ),
      backgroundColor: ColorStyle.backGroundColor,
      body: GetBuilder<CertificationController>(
        builder: (controller) {
          return controller.isLoading
              ? const LoadingWidget()
              : Container(
                  color: ColorStyle.whiteColor,
                  padding: EdgeInsetsStyle.edgeInsets(20, 7),
                  child: ListView(
                    children: [
                      Text(
                        '温馨提示:',
                        style: Styles.normalText_16,
                      ),
                      Box.vBox5,
                      Text(
                        '1.认证照需按照本人正面全脸清晰照片;\n2.认证照需按照示例图中手势，否则不通过\n3.封面照用于首页展示，请上传本人照片;\n4.封面照背景不能杂乱，必须露脸;\n5.不得上传带有水印的封面照，否则不会通',
                        style: Styles.greyText_12,
                      ),
                      Box.vBox15,
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceAround,
                        children: [
                          certificationDemoCamaraItem(),
                          certificationApplyCamaraItem()
                        ],
                      ),
                      Box.vBox30,
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceAround,
                        children: [
                          certificationDemoAvatarItem(),
                          certificationApplyAvatarItem()
                        ],
                      ),
                    ],
                  ));
        },
        assignId: true,
      ),
    );
  }

  Widget certificationDemoCamaraItem() {
    return Column(
      children: [
        Container(
            decoration: BoxDecoration(
              borderRadius: RadiusStyle.radiusAll(
                10,
              ),
              color: ColorStyle.d8d8d8Color,
            ),
            width: 130.w,
            height: 130.w,
            child: controller.certificationModel == null
                ? Image.asset(ImagePath.assetsDemoAvatar)
                : CachedNetworkImage(
                    imageUrl: SpUtil.getImageUrl(
                        controller.certificationModel!.demoCamara!))),
        Box.vBox5,
        Text(
          '示例图',
          style: Styles.normalText_14,
        ),
        Box.vBox5,
        Text(
          '（按照图中手势）',
          style: Styles.customStyle(const Color(0xFFFC3D2D), 14),
        ),
      ],
    );
  }

  Widget certificationApplyCamaraItem() {
    return Column(
      children: [
        GestureDetector(
          child: Container(
              decoration: BoxDecoration(
                borderRadius: RadiusStyle.radiusAll(
                  10,
                ),
                color: ColorStyle.d8d8d8Color,
              ),
              width: 130.w,
              height: 130.w,
              child: controller.certificationModel?.applyCamara == ''
                  ? Image.asset(ImagePath.assetsPhotoAdd)
                  : CachedNetworkImage(
                      imageUrl: SpUtil.getImageUrl(
                          controller.certificationModel!.applyCamara!),
                      fit: BoxFit.fitWidth,
                    )),
          onTap: () {
            controller.updateCaremaClick(context);
          },
        ),
        Box.vBox5,
        Text(
          '自拍',
          style: Styles.normalText_14,
        ),
        Box.vBox5,
        Text(
          '（不对外展示）',
          style: Styles.customStyle(const Color(0xFFFC3D2D), 14),
        ),
      ],
    );
  }

  Widget certificationDemoAvatarItem() {
    return Column(
      children: [
        Container(
            decoration: BoxDecoration(
              borderRadius: RadiusStyle.radiusAll(
                10,
              ),
              color: ColorStyle.d8d8d8Color,
            ),
            width: 130.w,
            height: 130.w,
            child: controller.certificationModel == null
                ? Image.asset(ImagePath.assetsDemoCamera)
                : CachedNetworkImage(
                    imageUrl: SpUtil.getImageUrl(
                        controller.certificationModel!.demoAvatar!))),
        Box.vBox5,
        Text(
          '示例图',
          style: Styles.normalText_14,
        ),
        Box.vBox5,
        Text(
          '（露全脸，背景清晰）',
          style: Styles.customStyle(const Color(0xFFFC3D2D), 14),
        ),
      ],
    );
  }

  Widget certificationApplyAvatarItem() {
    return Column(
      children: [
        GestureDetector(
          child: Container(
              decoration: BoxDecoration(
                borderRadius: RadiusStyle.radiusAll(
                  10,
                ),
                color: ColorStyle.d8d8d8Color,
              ),
              width: 130.w,
              height: 130.w,
              child: controller.certificationModel?.applyAvatar == ''
                  ? Image.asset(ImagePath.assetsPhotoAdd)
                  : CachedNetworkImage(
                      imageUrl: SpUtil.getImageUrl(
                          controller.certificationModel!.applyAvatar!),
                      fit: BoxFit.fitWidth)),
          onTap: () {
            controller.updateAvatarClick(context);
          },
        ),
        Box.vBox5,
        Text(
          '头像',
          style: Styles.normalText_14,
        ),
        Box.vBox5,
        Text(
          '（露全脸，背景清晰）',
          style: Styles.customStyle(const Color(0xFFFC3D2D), 14),
        ),
      ],
    );
  }
}
